<#import "/home/masterTemplate.ftl" as layout />
<#include "/macros/utils.ftl" />
<#import "../macros/spring.ftl" as spring />
<#include "./includes/utils.ftl" />

<#----><#include "/dumps/dump-util.ftl" />


<#assign scriptsObj>
	<#if isMobile()>

	<#else>
		require(["../js/modules/form", "../js/account/account"], function() {
	</#if>


	<#if !isMobile()>
		});
	</#if>
</#assign>
<#assign user = m_site.m_user />

<#function getCount exa_list isPending>
	<#assign counter = 0 />
	<#list exa_list as exam>
		<#if exam.finished == false && isPending == true>
			<#--counter for pending exams-->
			<#assign counter = counter + 1 />
		<#elseif exam.finished == true && isPending == false>
			<#--counter for finished exams-->
			<#assign counter = counter + 1 />
		</#if>
	</#list>
	<#return counter />
</#function>

<#if m_site.m_user.privileges == 1>
	<#assign index = "5"/>
<#else>
	<#assign index = "0" />
</#if>

<@layout.masterTemplate wtSection="account" wtSubsection="" title="" bodycss="" wrappercss="bg" section="account" subsection="" pagename="" color="" sectionIdx=index> 
	

	<div class="page-header">
		<h1>Account<small>Module</small></h1>
	</div>
	<div class="account-wrapper cf">
		<div class="col1-of-2">
			<div class="page-header bs-glyphicons cf">
					<h1>My Exams</h1>
					<#assign exams = getList(user.examsList) />
			</div>
			<div class="exam-summary well">
				<p>
					<label><strong>Total</strong></label>: ${exams?size!"0"}
				</p>
				<p>
					<label><strong>Pending</strong></label>: ${getCount(exams, true)}
				</p>
				<p>
					<label><strong>Finished</strong></label>: ${getCount(exams, false)}
				</p>
			</div>
			<div class="exams cf">
				
				<#list exams as exam>
					<@examItem exam />
				</#list>
			</div>
		</div>
		<div class="col2-of-2">
			<div class="page-header bs-glyphicons cf">					
				<h1>Personal Information </h1>
			</div>
			<div class="user-info">
				<div class="info cf">
					<p class="email_update">
						<label><strong>Email Address</strong></label>: ${user.email}
					</p>
					<p class="fullname_update">
						<label><strong>Fullname</strong></label>: ${user.firstName} ${user.lastName}
					</p>
					<p class="privilages_update">
						<label><strong>User type</strong></label>: 
						 	<#if user.privileges == 1>
						 		Admin
						 	</#if>
						 	<#if user.privileges == 2>
						 		Guest
						 	</#if>
						
					</p>
					<p class="badge_update">
						<label><strong>Badge number</strong></label: ${user.badgeID!"Not applicable"}>
					</p>
					<p class="password_update">
						<a href="<@spring.url '/password_update/' />">Change password</a>
					</p>

					<div><a class="btn btn-primary update right" role="button">update</a></div>
				</div>

				<#--update my personal information-->
				<div class="frm cf" data-async="true">
					<form action="<@spring.url '/update/add_input/' />" method="POST">
					  <div class="form-group">
					  	<label for="email">Email Address:</label>
					  	<input type="email" class="form-control" id="email" name="email" placeHolder="Email Address" title="Email address" required="required" maxlength="45"  data-rules="maxlength:45" value="${user.email}"/>
					  </div>
					  <div class="form-group">
					  	<label for="firstname">Firstname:</label>
					  	<input type="text" class="form-control" id="firstname" name="firstname" placeHolder="Firstname" title="First name" required="required"  maxlength="45" data-rules="maxlength:45" value="${user.firstName}"/>
					  </div>
					  <div class="form-group">
					  	<label for="lastname">Lastname:</label>
					  	<input type="text" class="form-control" id="lastname" name="lastname" placeHolder="Lastname" title="Last name" required="required"  maxlength="45" data-rules="maxlength:45" value="${user.lastName}"/>
					  </div>
					  <input type="hidden" class="form-control hide"  name="password" value="${user.password}"/>
					  <div class="formroup">
					  	<label for="badgeID">Badge number <span>(optional)</span>:</label>
					  	<input type="text" class="form-control" id="badgeID" name="badgeID" placeHolder="Badge number" title="Badge number"  maxlength="9" data-rules="number,maxlength:9"/>
					  </div>

						<#if user.privileges == 1>
							<input type="hidden" name="privileges" value="1"/>
						</#if>
						<#if user.privileges == 2>
							<input type="hidden" name="privileges" value="2"/>
						</#if>

					  <div class="formroup">
					  	<label for="password">Confirm password:</label>
					  	<input type="password" class="form-control" id="password" name="password" placeHolder="Password" required="required" title="Password"  maxlength="45" data-rules="number,maxlength:45"/>
					  </div>

					  <div><a class="btn btn-primary submit right" role="button">submit</a></div>
					</form>
				</div>
			</div>
		</div>
	</div>

	<#----><@dumper m_site "m_site" false true/>
</@layout.masterTemplate>